home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / formats / iff / newiff.lzh / NewIFF / NewIFF.lzh / newiff / apps / ScreenSave / ScreenSave.c < prev   
C/C++ Source or Header  |  1992-05-18  |  8KB  |  280 lines

  1. /* ScreenSave
  2.  * Saves front screen as an ILBM
  3.  * Requires linkage with several iffparse modules - See Makefile
  4.  */ 
  5. #define INTUI_V36_NAMES_ONLY
  6.  
  7. #include "iffp/ilbmapp.h"
  8.  
  9. #include <intuition/intuitionbase.h>
  10. #include <workbench/workbench.h>
  11. #include <graphics/gfxbase.h>
  12.  
  13. #include <clib/icon_protos.h>
  14.  
  15. #ifdef LATTICE
  16. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  17. int chkabort(void) { return(0); }  /* really */
  18. #endif
  19.  
  20. char *vers = "$VER: screensave 37.9";
  21. char *Copyright = 
  22.   "screensave v37.9 - supports new modes - Freely Redistributable";
  23. char *usage =
  24.  "Usage: screensave filename (filename -c[unit] for clipboard)\n" 
  25.  "Options: QUIET, NODELAY, NOICON, VIEWPORT, SEQUENCE (adds number to name)\n"
  26.  "Saves front screen (or ViewPort) after 10-sec delay (unless NODELAY).\n";
  27.  
  28. int mygets(char *s);
  29. void bye(UBYTE *s,int e);
  30. void cleanup(void);
  31.  
  32. struct Library    *IntuitionBase = NULL;
  33. struct Library    *GfxBase = NULL;
  34. struct Library    *IconBase = NULL;
  35. struct Library    *IFFParseBase = NULL;
  36.  
  37. struct ILBMInfo ilbm = {0};
  38.  
  39. BOOL fromWB, Quiet, NoDelay, NoIcon, Sequence, FrontVP;
  40.  
  41.  
  42.  
  43. #define INBUFSZ 128
  44. char nbuf[INBUFSZ];
  45.  
  46. /* Data for project icon for saved ILBM
  47.  *
  48.  */
  49. UWORD ILBMI1Data[] =
  50. {
  51. /* Plane 0 */
  52.     0x0000,0x0000,0x0000,0x0001,0x0000,0x0000,0x0000,0x0003,
  53.     0x0FFF,0xFFFF,0xFFFF,0xFFF3,0x0FFF,0x0000,0x0000,0xFFF3,
  54.     0x0FFC,0x0000,0x0000,0x3FF3,0x0FE0,0x0E80,0xF800,0x07F3,
  55.     0x0F80,0x1C01,0x8C00,0x01F3,0x0F00,0x0001,0x8C00,0x00F3,
  56.     0x0600,0x0000,0x0600,0x0063,0x0600,0x0003,0xBC00,0x0063,
  57.     0x0600,0x0001,0xFC00,0x0063,0x0600,0x0000,0xFC00,0x0063,
  58.     0x0600,0x1FC1,0xFE40,0x0063,0x0600,0x1DC1,0xFE20,0x0063,
  59.     0x0600,0x1CE3,0xFF12,0x0063,0x0F00,0x1CE0,0x004F,0xC0F3,
  60.     0x0F80,0x1CE0,0x002F,0x01F3,0x0FE0,0x0E78,0x423D,0x07F3,
  61.     0x0FFC,0x0000,0x0000,0x3FF3,0x0FFF,0x0000,0x0000,0xFFF3,
  62.     0x0FFF,0xFFFF,0xFFFF,0xFFF3,0x0000,0x0000,0x0000,0x0003,
  63.     0x7FFF,0xFFFF,0xFFFF,0xFFFF,
  64. /* Plane 1 */
  65.     0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xD555,0x5555,0x5555,0x5554,
  66.     0xD000,0x0000,0x0000,0x0004,0xD3FC,0xFFFF,0xFFFF,0x3FC4,
  67.     0xD3C0,0x0000,0x0000,0x03C4,0xD300,0x0100,0xF800,0x00C4,
  68.     0xD300,0x0381,0xFC00,0x00C4,0xD080,0x0701,0xFC00,0x0104,
  69.     0xD180,0xF883,0xFE00,0x0194,0xD181,0xDF80,0x4700,0x0194,
  70.     0xD181,0xDF82,0x0180,0x0194,0xD180,0x6F82,0x00C0,0x0194,
  71.     0xD180,0x0002,0x0020,0x0194,0xD180,0x0000,0x0000,0x0194,
  72.     0xD180,0x0000,0x0002,0x0194,0xD080,0x0000,0xCC46,0xC104,
  73.     0xD300,0x0000,0xCC2F,0x00C4,0xD300,0x0E78,0x883D,0x00C4,
  74.     0xD3C0,0x0000,0x0000,0x03C4,0xD3FC,0xFFFF,0xFFFF,0x3FC4,
  75.     0xD000,0x0000,0x0000,0x0004,0xD555,0x5555,0x5555,0x5554,
  76.     0x8000,0x0000,0x0000,0x0000,
  77. };
  78.  
  79. struct Image ILBMI1 =
  80. {
  81.     0, 0,            /* Upper left corner */
  82.     64, 23, 2,            /* Width, Height, Depth */
  83.     ILBMI1Data,            /* Image data */
  84.     0x0003, 0x0000,        /* PlanePick, PlaneOnOff */
  85.     NULL            /* Next image */
  86. };
  87.  
  88. UBYTE *ILBMTools[] =
  89. {
  90.     "FILETYPE=ILBM",
  91.     NULL
  92. };
  93.  
  94. struct DiskObject ILBMobject =
  95. {
  96.     WB_DISKMAGIC,        /* Magic Number */
  97.     WB_DISKVERSION,        /* Version */
  98.     {                /* Embedded Gadget Structure */
  99.     NULL,            /* Next Gadget Pointer */
  100.     0, 0, 64, 24,        /* Left,Top,Width,Height */
  101.     GFLG_GADGIMAGE | GADGBACKFILL,            /* Flags */
  102.     GACT_RELVERIFY | GACT_IMMEDIATE,    /* Activation Flags */
  103.     GTYP_BOOLGADGET,                /* Gadget Type */
  104.     (APTR)&ILBMI1,    /* Render Image */
  105.     NULL,            /* Select Image */
  106.     NULL,            /* Gadget Text */
  107.     NULL,            /* Mutual Exclude */
  108.     NULL,            /* Special Info */
  109.     0,            /* Gadget ID */
  110.     NULL,            /* User Data */
  111.     },
  112.     WBPROJECT,            /* Icon Type */
  113.     "Display",            /* Default Tool */
  114.     ILBMTools,            /* Tool Type Array */
  115.     NO_ICON_POSITION,        /* Current X */
  116.     NO_ICON_POSITION,        /* Current Y */
  117.     NULL,            /* Drawer Structure */
  118.     NULL,            /* Tool Window */
  119.     0                /* Stack Size */
  120. };
  121.  
  122.  
  123.  
  124. void main(int argc, char **argv)
  125.    {
  126.    struct View     *frontview;
  127.    struct ViewPort *frontvp;
  128.    struct BitMap   *frontbitmap;
  129.    UWORD       *frontcolortable;
  130.    struct Screen   *frontScreen;
  131.    LONG        error = 0L, seqlock;
  132.    char         *filename;
  133.    int l, k;
  134.  
  135.    fromWB = (argc==0) ? TRUE : FALSE;
  136.  
  137.  
  138.    if(!(IntuitionBase = OpenLibrary("intuition.library", 0)))
  139.       bye("Can't open intuition library.\n",RETURN_WARN);
  140.       
  141.    if(!(GfxBase = OpenLibrary("graphics.library",0)))
  142.       bye("Can't open graphics library.\n",RETURN_WARN);
  143.  
  144.    if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  145.       bye("Can't open iffparse library.\n",RETURN_WARN);
  146.  
  147.    if(!(IconBase = OpenLibrary("icon.library",0)))
  148.       bye("Can't open icon library.\n",RETURN_WARN);
  149.  
  150.    if(!(ilbm.ParseInfo.iff = AllocIFF()))
  151.       bye(IFFerr(IFFERR_NOMEM),RETURN_WARN);
  152.  
  153.    if(argc>1)                 /* Passed filename via command line  */
  154.       {
  155.       if(argv[1][0]=='?') 
  156.         {
  157.         printf("%s\n%s\n",Copyright,usage);
  158.         bye("\n",RETURN_OK);
  159.         }
  160.       else filename = argv[1];
  161.  
  162.       NoDelay = NoIcon = Quiet = Sequence = FrontVP = FALSE;
  163.       for(k=2; k < (argc); k++)
  164.     {
  165.     if(!(stricmp(argv[k],"NODELAY")))     NoDelay  = TRUE;
  166.     else if(!(stricmp(argv[k],"NOICON")))     NoIcon   = TRUE;
  167.     else if(!(stricmp(argv[k],"QUIET")))     Quiet    = TRUE;
  168.     else if(!(stricmp(argv[k],"SEQUENCE")))     Sequence = TRUE;
  169.     else if(!(stricmp(argv[k],"VIEWPORT"))) FrontVP = TRUE;
  170.     }
  171.       if(Sequence)
  172.     {
  173.     for(k=1; k<9999; k++)
  174.         {
  175.         sprintf(nbuf,"%s%04ld",filename,k);
  176.         if(seqlock = Lock(nbuf,ACCESS_READ))    UnLock(seqlock);
  177.         else break;
  178.         }
  179.     filename = nbuf;
  180.     }
  181.       }
  182.    else
  183.       {
  184.       printf("%s\n%s\n",Copyright,usage);
  185.       printf("Enter filename for save: ");
  186.       l = mygets(&nbuf[0]);
  187.  
  188.       if(l==0)                /* No filename - Exit */
  189.          {
  190.          bye("\nScreen not saved, filename required\n",RETURN_FAIL);
  191.          }
  192.       else
  193.          {
  194.          filename = &nbuf[0];
  195.          }
  196.       }
  197.      
  198.    if(!NoDelay)    Delay(500);
  199.  
  200.    Forbid();
  201.    frontScreen  = ((struct IntuitionBase *)IntuitionBase)->FirstScreen;
  202.    Permit();
  203.  
  204.  
  205.    if(FrontVP)
  206.     {
  207.     frontview = ((struct GfxBase *)GfxBase)->ActiView;
  208.     frontvp = frontview->ViewPort;
  209.     while((frontvp->Next)&&(frontvp->Modes & VP_HIDE))
  210.         frontvp = frontvp->Next;
  211.     frontbitmap = frontvp->RasInfo->BitMap;
  212.     frontcolortable = frontvp->ColorMap->ColorTable;
  213.     if(error = saveilbm(&ilbm,
  214.                 frontbitmap, (ULONG)frontvp->Modes,
  215.                 frontvp->DWidth, frontbitmap->Rows,
  216.                 frontvp->DWidth, frontbitmap->Rows,
  217.                 frontcolortable, frontvp->ColorMap->Count, 4,
  218.                 0, 0,
  219.                 NULL,NULL,
  220.                 filename))
  221.     printf("%s\n",IFFerr(error));
  222.     }
  223.    else if(error = screensave(&ilbm, frontScreen,
  224.                 NULL, NULL,
  225.                 filename))
  226.     {
  227.     printf("%s\n",IFFerr(error));
  228.     }
  229.  
  230.    if(! error)
  231.     {
  232.           if(!Quiet) printf("%s saved as %s... ",
  233.             FrontVP ? "Viewport" : "Screen",filename);
  234.     if((!NoIcon)&&(filename[0]!='-')&&(filename[1]!='c')) /* not clipboard */
  235.         {
  236.               if(!(PutDiskObject(filename,&ILBMobject)))
  237.                 {
  238.                 bye("Error saving icon\n",RETURN_WARN);
  239.                 }
  240.            if(!Quiet) printf("Icon saved\n");
  241.         }
  242.     else if(!Quiet) printf("\n");
  243.           bye("",RETURN_OK);
  244.           }
  245.     }
  246.  
  247.  
  248. void bye(UBYTE *s,int e)
  249.    {
  250.    if(s&&(*s)) printf("%s\n",s);
  251.    if ((fromWB)&&(*s))    /* Wait so user can read messages */
  252.       {
  253.       printf("\nPRESS RETURN TO EXIT\n");
  254.       mygets(&nbuf[0]);
  255.       }
  256.    cleanup();
  257.    exit(e);
  258.    }
  259.  
  260. void cleanup()
  261.    {
  262.    if(ilbm.ParseInfo.iff)    FreeIFF(ilbm.ParseInfo.iff);
  263.  
  264.    if(GfxBase)        CloseLibrary(GfxBase);
  265.    if(IntuitionBase)    CloseLibrary(IntuitionBase);
  266.    if(IconBase)        CloseLibrary(IconBase);
  267.    if(IFFParseBase)    CloseLibrary(IFFParseBase);
  268.    }
  269.  
  270.  
  271. int mygets(char *s)
  272.    {
  273.    int l = 0, max = INBUFSZ - 1;
  274.  
  275.    while (((*s = getchar()) !='\n' )&&(l < max)) s++, l++;
  276.    *s = NULL;
  277.    return(l);
  278.    }
  279.  
  280.